package com.evry.config;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

import com.evry.repository.CollateralItemDao;
import com.evry.repository.CollateralItemDaoImpl;
import com.evry.service.CollateralItemManager;
import com.evry.service.SimpleCollateralItemManager;
import com.evry.support.Fractions;
import com.evry.support.FractionsImpl;

@Configuration
@Profile("production")
public class AppProdConfig implements DataConfig {

    private static final String URL = "jdbc:hsqldb:hsql://localhost";
    private static final String USERNAME = "sa";
    private static final String PASSWORD = "";
    
    @Bean
    public CollateralItemDao collateralItemDao() {
        return new CollateralItemDaoImpl(dataSource());
    }
    
    @Bean
    public CollateralItemManager collateralItemManager() {
        return new SimpleCollateralItemManager();
    }
    
    @Bean
    public Fractions fractions() {
        return new FractionsImpl();
    }

	@Bean
	@Override
    public DataSource dataSource() {
		BasicDataSource source = new BasicDataSource();
		source.setDriverClassName("org.hsqldb.jdbcDriver");
		source.setUrl(URL);
		source.setUsername(USERNAME);
		source.setPassword(PASSWORD);
		return (DataSource) source;
	}
}
